1. Field of the Invention
The present invention relates to an image encoding apparatus, a method and a memory medium therefor, for example an apparatus capable of generating image data and storing image data of plural images, as represented by a digital camera.
2. Related Background Art
Various digital cameras are already commercialized, and such camera is provided therein with a non-volatile semiconductor memory or a magnetic disk, as non-volatile memory means for recording and storing the image data of plural images.
The digital image data, generated by a solid-state image pickup device such as CCD provided in many digital camera, are extremely large in the data amount and are therefore usually recorded or stored in the above-mentioned non-volatile memory means after a compression encoding process is performed on the original image data to an extent that such compression is not clearly observable or does not cause distortion at the expanded restoration of the image.
As a representative method for compression encoding of the digital image data, there is known a compression encoding method including block division, orthogonal transformation and entropy encoding utilizing variable length codes.
In such representative compression encoding method, the original digital image data of an image are divided into plural rectangular blocks of a predetermined size, determining the two-dimensional orthogonal transformation coefficients for each block, then dividing and quantizing the orthogonal transformation coefficient, rearranged in a frequency coordinate system, with the quantization coefficients provided based on the human visual characteristics, and assigning predetermined variable length codes to the sequence of thus quantized orthogonal transformation coefficients, thereby generating the compression encoded image data as the final result.
However, the above-described compression encoding process requires an enormous number of operations. Thus, in case that such the compression encoding process is realized either by a program working on a general processor or by an exclusive hardware, there is generally employed temporary memory means capable of high-speed reading and writing operations such as a DRAM, in order to increase the processing speed.
In such temporary memory means, there are temporarily stored, in respectively assigned areas, the original image data entered from the image pickup device, the interim result of operations represented by the orthogonal transformation coefficients, and the compression encoded data obtained as a result of the compression encoding process.
After the completion of the above-described compression encoding process, the compression encoded data developed on the temporary memory means as the final result are transferred to and stored in the aforementioned non-volatile memory means for the purpose of final storage. Thus a serial photographing operation is completed and the system returns to a state capable of initiating the next photographing operation of an image.
In most digital cameras, the total capacity of the temporary memory means is naturally set at the minimum necessary value in consideration of the cost. For the original image data and for the interim result of operations, that always require area of fixed capacities, there are assigned areas having respectively fixed capacities in the temporary memory means.
On the other hand, for the compression encoded data having a variable length, there is assigned, in the temporary memory means, an area of a capacity corresponding to a data length assumed to be sufficient to a considerable extent.
However, the data length of the above-described compression encoded data of variable length varies significantly according to the frequency distribution and deviation of the original image data entered from the image pickup device, and it is already known that the size of the compression encoded data fluctuates by the statistical properties of the original image data even if the compression encoding process is executed with same parameters.
The digital camera utilizing such compression encoding process is generally provided with plural photographing modes (compression encoding modes). Such plural photographing modes include, for example, a photographing mode with a low compression rate, capable of recording high-quality image data with a low compression distortion though incapable of recording a large number of images, and a photographing mode with a relatively high compression rate, capable of recording a large number of images with image data of a relatively large compression distortion. The corresonding compression encoding process is executed for each mode.
In the aforementioned representative compression encoding method, a representative parameter capable of easily controlling the compression rate for given original image data is the value of the quantization coefficient. Since this value corresponds to the divisor of the division in the quantization process, the compression rate can be elevated or lowered by performing quantization respectively with a large or small quantization coefficient.
Usually, the operator of the digital camera selects one of the aforementioned plural photographing modes prior to the photographing operation. In such operation, the information necessitated by the operator includes the currently selected photographing mode and the number of pictures that can be taken and recorded with such photographing mode. Such information is usually determined uniquely by the available capacity of the non-volatile memory means, and the information display means such as an LCD equipped on the digital camera usually displays the kind of the photographing mode and the number of pictures that can be taken.
In the compression encoding process executed in the digital camera for the image data, it is essential to execute the compression encoding in such a manner that the data amount of the compression encoded image data does not exceed the upper limit value of a predetermined range. Such control achieved by data amount control means allows to secure the value displayed to the operator as the remaining number of pictures that can be taken.
At the same time it is also essential to execute the compression encoding in such a manner that the amount of the compression encoded image data does not become lower than the lower limit value of the predetermined range. Such control achieved by the data amount control means allows to prevent generation of the compression encoded data having an unnecessarily high compression rate and accordingly a large compression distortion.
In the conventional digital cameras, in order to obtain the compression encoded data of a desired data amount, there is employed a method of predicting the quantization coefficient capable of generating the desired data amount, based on the amount of the compression encoded data obtained by executing the compression encoding process on a part of the image data of an image, and executing the compression encoding process again with such new quantization coefficient, or a method of repeating the compression encoding process by varying the quantization coefficient each time, until the amount of the compression encode data becomes contained in the predetermined range, or a method of predicting an optimum quantization coefficient based on the statistical property (for example activity in each block) of the original image data, separately determined quantitatively.
The orthogonal transformation coefficient generated by orthogonal transformation is independent from the succeeding quantizing operation, and remains constant for given original image data. Consequently, for example in case of executing the compression encoding process plural times for the given original image data, the processing speed can be effectively increased by a method of storing the orthogonal transformation coefficient, generated at a first compression encoding process, in the temporary memory means, and, in the second and subsequent compression encoding processes, to employ thus stored orthogonal transformation coefficient, thereby dispensing with the operation relating to the orthogonal transformation.
However, in any of these methods, there may result an overflowing situation where the amount of the compression encoded data of variable length, obtained by the variable length encoding, exceeds the upper limit of the data amount estimated in advance and thus the compression encoded data consumes all the area assigned in the temporary memory means still in the course of the compression encoding process. Such overflow tends to occur particularly in the encoding process of the first time, since the compression encoding process is executed with a predetermined quantization coefficient.
When such situation is encountered, most digital cameras immediately terminate the currently executed compression encoding process and execute an exceptional process of repeating the compression encoding process by uniquely changing the quantization coefficient to a larger value. In the digital camera executing the compression encoding process by a program working on a general processor, the process time required for compression encoding of the original image data of an image is generally not negligibly small. It is therefore important to shorten such process time in order to improve the operability, but there is also required the exceptional process of interrupting the meaningless compression encoding process as explained above.
Also for avoiding the situation itself of such exceptional process, there is employed a method of assigning, in the temporary memory means, an area of a sufficiently large capacity corresponding to the theoretical upper limit of the compression encoded data, though such method is disadvantageous in cost.
If the compression encoding process is terminated immediately when the remaining capacity of the area assigned in the temporary memory means for the compression encoded data of variable length is consumed as explained in the foregoing, there remains unknown the total data amount of the compression encoded data, that should have been obtained with the parameter or the quantization coefficient selected for such terminated process.
Consequently the accuracy of prediction of the new quantization coefficient becomes naturally worse, and, in the repeated compression encoding process with thus determined quantization coefficient, there cannot be prevented danger of encountering an overflow situation where the area assigned in the temporary memory means is all consumed or an underflow situation of generating the compression encoded data of an unnecessarily small data amount.
Also in case the compression encoding process is immediately terminated as in the aforementioned conventional example, the storage of the orthogonal transformation coefficient into the temporary memory means is also interrupted incompletely, so that, in the repeated compression encoding process, the process has to be started from the orthogonal transformation operation requiring a large operation load.
In consideration of the foregoing, the object of the present invention is to provide an image encoding apparatus, a method therefor, and a memory medium storing an encoding program therefor, capable of obtaining an optimum parameter for repeating the compression encoding based on more accurate information even in case the amount of the encoded data exceeds the data memory capacity of memory means for storing such encoded data, thereby enabling the compression encoding within the data memory capacity while giving priority to the image quality.
The above-mentioned object can be attained, according to one aspect of the present invention, by providing an image encoding apparatus/method characterized by inputting image data, quantizing the image data, variable length encoding the quantized image data, detecting the code length of the encoded image data, storing the encoded image data in a predetermined memory area of memory means, discriminating whether the detected code length exceeds the memory capacity of the predetermined memory area, then, in case the memory capacity is exceeded, interrupting the memory operation into the memory area, while continuing the encoding process and the detecting process and setting the quantization parameter for the quantization process according to the result of detection of the detection process.
According to another aspect of the present invention, there is also provided a memory medium storing a code of a quantization step of quantizing image data, a code of an encoding step of variable length encoding the quantized image data, a code of a detection step of detecting the code length of the encoded image data, a code of a memory step of storing the encoded image data in a predetermined memory area of memory means, a code of a discrimination step of discriminating whether the detected code length exceeds the memory capacity of the predetermined memory area, and a code of a control step of in case the discrimination step identifies that the memory capacity is exceeded, interrupting the memory operation of the memory step while continuing the encoding step and the detection step and setting the quantization parameter in the quantization step according to the result of detection in the detection step.